/****************************************************
	文件：BehaviorFactory.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/5/15 23:59:27
	功能：行为生产工厂
*****************************************************/

using System;
using UnityEngine;

namespace AIBehavior
{
    public class BehaviorFactory
    {
        public static IEntity Create(AIData data, BehaviorType behaviorType)
        {
            IFactory factory = CreateObj<IFactory>(behaviorType.ToString());
            return factory.Create(data);
        }

        private static T CreateObj<T>(string className) where T : class
        {
            string fullName = Consts.NAME_SPACE_AIBEHAVIOR + "." + className + Consts.BEHAVIOR_FACTORY_SUFFIX;
            try
            {
                T ret = Activator.CreateInstance(Type.GetType(fullName)) as T;
                return ret;
            }
            catch (Exception e)
            {
                Debug.LogErrorFormat("反射创建对象出错！class name:{0}\nError:{0}", fullName, e.ToString());
                return null;
            }
        }
    }
}